<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录入口</title>
    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.css">
    <!-- Ionicons -->
    <link rel="stylesheet" th:href="@{/dist/css/ionicons.min.css}"/>
    <!-- Theme style -->
    <link rel="stylesheet" th:href="@{/dist/css/adminlte.min.css}"/>
    <!-- jquery -->
    <script type="text/javascript" th:src="@{/plugins/jquery/jquery.min.js}"></script>
    <script type="text/javascript" th:src="@{/plugins/bootstrap/js/bootstrap.min.js}"></script>
    <!-- jquery-validator -->
    <script type="text/javascript" th:src="@{/plugins/jquery-validation/jquery.validate.min.js}"></script>
    <script type="text/javascript" th:src="@{/plugins/jquery-validation/localization/messages_zh.min.js}"></script>
    <!-- sweetalert -->
    <script type="text/javascript" th:src="@{/plugins/sweetalert/sweetalert.min.js}"></script>
    <!-- layer -->
    <script type="text/javascript" th:src="@{/plugins/layer/layer.js}"></script>
    <!-- md5.js -->
    <script type="text/javascript" th:src="@{/dist/js/plugins/md5.min.js}"></script>
    <!-- common.js -->
    <script type="text/javascript" th:src="@{/dist/js/common.js}"></script>
    <style>
        canvas {
            display: block;
            vertical-align: bottom;
        }
        #particles {
            background-color: cornflowerblue;
            position: absolute;
            top: 0;
            width: 100%;
            height: 100%;
            z-index: -1;
        }
    </style>

</head>
<body class="hold-transition login-page">
<!--引入粒子背景-->
<div id="particles">
</div>
<div class="login-box">
    <div class="login-logo" style="color: #382124;">
        <h1>登录入口</h1>
    </div>
    <!-- /.login-logo -->
    <div class="card">
        <div class="card-body login-card-body">
            <p class="login-box-msg"> Seckill , Let's Go !</p>
            <form name="loginForm" id="loginForm" method="post">
<!--                <div th:if="${not #strings.isEmpty(session.errorMsg)}" class="form-group">-->
<!--                    <div class="alert alert-danger" th:text="${session.errorMsg}"></div>-->
<!--                </div>-->
                <div class="form-group has-feedback">
                    <span class="fa fa-user form-control-feedback"></span>
                    <input type="text" id="mobile" name="mobile" class="form-control" placeholder="请输入账号"
                           required="true">
                </div>
                <div class="form-group has-feedback">
                    <span class="fa fa-lock form-control-feedback"></span>
                    <input type="password" id="password" name="password" class="form-control" placeholder="请输入密码"
                           required="true">
                </div>
<!--                <div class="row">-->
<!--                    <div class="col-6">-->
<!--                        <input type="text" class="form-control" name="verifyCode" placeholder="请输入验证码" required="true">-->
<!--                    </div>-->
<!--                    <div class="col-6">-->
<!--                        <img alt="单击图片刷新！" class="pointer" th:src="@{/common/kaptcha}"-->
<!--                             onclick="this.src='/common/kaptcha?d='+new Date()*1">-->
<!--                    </div>-->
<!--                </div>-->
                <div class="form-group has-feedback"></div>
                <div class="row">
                    <div class="col-8">
                        <div class="col-6">
                            <a type="button" class="btn btn-success btn-block btn-flat" href="./register.html">注册</a>
                        </div>
                    </div>
                    <div class="col-4">
                        <button type="submit" class="btn btn-primary btn-block btn-float" onclick="login()">登录
                        </button>
                    </div>
                </div>
                <div class="col-8">
                    <p th:text="'网站访问次数:'+${count}" style="margin-bottom:0;margin-top: 15px"></p>
                </div>
            </form>
        </div>
        <!-- /.login-card-body -->
    </div>
</div>
</body>
<script>
    function login() {
        $("#loginForm").validate({
            submitHandler:function(form){
                doLogin();
            }
        });
    }
    function doLogin() {
        // 加载中
        g_showLoading();
        let mobile=$("#mobile").val();
        let inputPass=$("#password").val();
        let salt=g_passsword_salt;
        //规则必须与后端定义的加密规制一致
        let passStr="" + salt.charAt(0) + salt.charAt(2) + inputPass + salt.charAt(5) + salt.charAt(4);
        //md5加密，如果绕过前端，比如使用swagger,那么加密是没有效果的
        let password=md5(passStr);
        console.log("加密密码:"+password);
        $.ajax({
            url: "/user/login",
            type: "POST",
            data: {
                mobile: mobile,
                password: password
            },
            success: function (data) {
                console.log(111);
                layer.closeAll();
                if (data.code == 200) {
                    layer.msg("成功");
                    window.location.href="/goods/to_list";
                } else {
                    swal(data.msg,{
                        icon:"error",
                    });
                    // layer.msg(data.msg);
                }
            },
            error: function () {
                swal("操作失败",{
                    icon:"error"
                });
                layer.closeAll();
            }
        });
    }
</script>
<!--粒子背景-->
<script type="text/javascript" th:src="@{/dist/js/plugins/particles.js}"></script>
<script type="text/javascript" th:src="@{/dist/js/plugins/login-bg-particles.js}"></script>
</html>